package day019.homework.p7;

import java.io.FileOutputStream;
import java.io.IOException;

public class Test {
    public static void main(String[] args) {
        method1();
        method2();
    }

    private static void method1() {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("D:\\test007.txt");
            fos.write("HelloWorld!".getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method2() {
        try (
                FileOutputStream fos = new FileOutputStream("D:\\test008.txt");
        ) {
            fos.write("HelloWorld!".getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
